package com.hongawen.channel.socket;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.SocketChannel;
import java.nio.charset.StandardCharsets;

/**
 * @author hongawen
 * @version 1.0
 * @data 2025/4/30 11:32
 */
public class ClientSocket {

    /**
     * 简介：模拟socket客户端，去链接服务器端
     *
     * @param args .
     */
    public static void main(String[] args) {
        try (SocketChannel socketChannel = SocketChannel.open();) {
            socketChannel.connect(new InetSocketAddress("127.0.0.1", 8819));
            System.out.println("客户端连接成功");
            socketChannel.write(StandardCharsets.UTF_8.encode("我是客户端:" + Thread.currentThread()));
            System.out.println("客户端发送数据成功");
            socketChannel.write(StandardCharsets.UTF_8.encode("我是客户端11:" + Thread.currentThread()));
            System.out.println("客户端发送数据成功11");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
